home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Http Server / •OT_Classes / TNetworkAcceptor.h < prev    next >
Encoding:
Text File  |  1996-01-11  |  3.9 KB  |  141 lines  |  [TEXT/CWIE]

  1. //    TNetworkAcceptor.h - Macintosh OpenTransport Network Acceptor class object
  2. // 
  3. // Apple Macintosh Developer Technical Support
  4. // Written by:  Vinne Moscaritolo
  5. //
  6. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  7. //
  8. // You may incorporate this sample code into your applications without
  9. // restriction, though the sample code has been provided "AS IS" and the
  10. // responsibility for its operation is 100% yours.  However, what you are
  11. // not permitted to do is to redistribute the source as "DSC Sample Code"
  12. // after having made changes. If you're going to re-distribute the source,
  13. // we require that you make it clear in the source that the code was
  14. // descended from Apple Sample Code, but that you've made changes.
  15. // 
  16.  
  17. #ifndef _H_TNETWORKACCEPTOR
  18. #define _H_TNETWORKACCEPTOR
  19.  
  20. #include "TNetworkEventHandler.h"
  21. #include "TNetworkEndpointDescriptor.h"
  22. #include "TNetworkSession.h"
  23. #include "TGMT.h"
  24.  
  25. #define kSessionStackSpace    8192
  26.  
  27. class TSessionPrefs
  28. {
  29. public: 
  30.     TSessionPrefs():
  31.         fMaxFreeSessions(4),
  32.         fBuildSessions(4),
  33.         fMaxOutStanding(256)
  34.          {};
  35.         
  36.         short        fMaxFreeSessions;        // max Free Sessions cached
  37.         short        fBuildSessions;            // Free Session to prebuild
  38.         short        fMaxOutStanding;        // max outstanding connections.
  39. };
  40.   
  41. struct TAcceptorInfo
  42. {
  43.     TAcceptorInfo():
  44.         fActiveSessions(0),
  45.         fFreeSessions(0),
  46.         fAcceptedSessions(0),
  47.         fRejectedSessions(0),
  48.         fDisconSessions(0),
  49.         fUpTime(0){};
  50.         
  51.         short            fActiveSessions ;
  52.         short            fFreeSessions;
  53.         int                fAcceptedSessions;
  54.         int                fRejectedSessions;
  55.         int                fDisconSessions;
  56. unsigned long fUpTime;
  57.         
  58. };
  59.     
  60. typedef struct TAcceptorInfo    TAcceptorInfo;
  61.  
  62.         
  63. //
  64. // TNetworkAcceptor  - OpenTransport Network Acceptor class 
  65. //
  66. class TNetworkAcceptor : public TNetworkEventHandler
  67. {
  68.  
  69. public:
  70.     enum { kSessionAvailable = (OTEventCode) kPRIVATEEVENT,
  71.                  kOtherEvent};
  72.     
  73.  
  74. //     CONSTRUCTORS AND DESTRUCTORS
  75. public:
  76.                     TNetworkAcceptor(char* ServerName = 0):
  77.                                 fEPD(NULL),
  78.                                 fEndPoint(kOTInvalidEndpointRef),
  79.                                 fPending(kNonePending),
  80.                                 fLocalAddress(NULL)
  81.                                 {};
  82.                                         
  83.     virtual    ~TNetworkAcceptor();
  84.     
  85. // HIGH LEVEL FUNCTIONS
  86. public:
  87.     virtual    void     Open(TNetworkEndpointDescriptor*);
  88.  
  89. // ACCESSORS
  90. public:
  91.     TNetworkEndpointDescriptor*    GetEPD()     {return fEPD; };
  92.     Boolean                                            GetStats( TAcceptorInfo* );
  93.     
  94. // ABSTRACT FUNCTIONS
  95. protected:
  96.         virtual TNetworkSession* SessionFactory() = 0;
  97.                        
  98. // FUNCTIONS FROM TNetworkEventHandler
  99. private:
  100.     void     HandleEvent(TNetworkEvent* );
  101.  
  102. // EVENT MANGEMENT FUNCTIONS
  103. private:
  104.     void EventOpenComplete             (TNetworkEvent* );
  105.     void EventBindComplete             (TNetworkEvent* );
  106.     void EventListen                      (TNetworkEvent* );
  107.     void EventAcceptComplete        (TNetworkEvent* );
  108.     void EventDisconnect                (TNetworkEvent* );
  109.     void EventDisconnectComplete(TNetworkEvent* );
  110.     void EventUnbindComplete        (TNetworkEvent* );
  111.     void EventSessionAvailable     (TNetworkEvent* );        // private event
  112.     void EventOther                            (TNetworkEvent* );        // Debug event
  113.     
  114. // OPEN TRANSPORT CALLBACK
  115.     static pascal void NotifyProc (TNetworkAcceptor* , OTEventCode , OTResult , void* );
  116.  
  117. // PRIVATE FUNCTIONS
  118.     void DoListen                            ( TNetworkSession *);
  119.     
  120. // PRIVATE FIELDS
  121. private:
  122.     enum  {kUnBound = -1, kNonePending = 0} ;
  123.  
  124. TNetworkEndpointDescriptor*    fEPD;                                // Endpoint descriptor
  125.                     EndpointRef             fEndPoint;                    // OT Endpoint
  126.                     TEndpointInfo            fInfo;                            // Endpoint information
  127.                     TList                         fActiveSessions;        // list of active sessions
  128.                     TList                         fFreeSessions;            // list of cached free sessions
  129.                     TAddr*                        fLocalAddress;            // Address bound to
  130.                     TBind                            fReqBind;                        // Requested Address
  131.                     TBind                            fRetBind;                        // What we really gt
  132.                     int                                fPending;                        // listen events pending.
  133.                     TSessionPrefs            fPrefs;                            // Session Preferences
  134.                     TAcceptorInfo            fStats;                            // Usage Statisics
  135.                     TGmt                            fStartTime;                    // Time Server Came Up
  136.                     
  137. };
  138.  
  139.  
  140. #endif
  141.